package com.dwxt.community.admin.controller;

import com.dwxt.common.base.*;
import com.dwxt.community.entity.dto.*;
import com.dwxt.community.service.supervisor.*;
import com.github.pagehelper.*;
import org.apache.commons.lang3.*;
import org.springframework.beans.factory.annotation.*;
import org.springframework.web.bind.annotation.*;

import javax.validation.*;

/**
 * @program: intelligentcity
 * @description: 督导员、巡检员后台
 * @author
 * @create: 2020/04/18
 */
@RestController
@RequestMapping("/cms/admin/supervisor")
public class SupervisorControllerAdmin {

    @Autowired
    private SupervisorUserService supervisorUserService;

    /**
     * showdoc
     *
     * @return {"status":200,"msg":"SUCCESS","data":[{"id":"158711800317312","phone":"15977772222","username":"巡检员","workId":"3456","roleId":"158711800398756","idCard":"110101199003074397","createTime":"2020-04-17 18:38:15","updateTime":"2020-04-17 18:38:10","isDudaoyuan":0,"isXunjianyuan":1,"sumUpDoorPropaganda":0},{"id":"158711800317392","phone":"15922227777","username":"督导员","workId":"1234","roleId":"158711800303859","idCard":"110101199003075373","createTime":"2020-04-17 18:15:30","updateTime":"2020-04-17 18:08:17","superiorId":"158711800317312","isDudaoyuan":1,"isXunjianyuan":0,"sumUpDoorPropaganda":200}]}
     * @catalog 社区后台管理/督导员、巡检员管理
     * @title 员工列表
     * @param workId 非必须 String 工号
     * @param roleName 非必须 String 角色名
     * @param username 非必须 String 用户名
     * @method get
     * @description 员工列表
     * @url /cms/admin/supervisor/get
     */
    @RequestMapping("/get")
    public BaseResult get(@RequestParam(defaultValue = "1") Integer pageNum,
                          @RequestParam(defaultValue = "10") Integer pageSize,
                          String workId,
                          String roleName,
                          String username) {
        return BaseResult.ok(new PageInfo<>(supervisorUserService.selectAll(pageNum, pageSize, workId, roleName,username)));
    }

    /**
     * showdoc
     *
     * @return {"status":200,"msg":"SUCCESS","data":[{"id":"158711800317392","phone":"15922227777","username":"郭富城","workId":"1234","password":"E10ADC3949BA59ABBE56E057F20F883E","roleId":"158711800398756","idCard":"110101199003075373","createTime":"2020-04-21 10:05:16","updateTime":"2020-04-17 18:08:17","sumUpDoorPropaganda":0},{"id":"158746073666997","phone":"15999999999","username":"孙燕姿","workId":"123","password":"E10ADC3949BA59ABBE56E057F20F883E","roleId":"158711800398756","idCard":"110101199003074135","createTime":"2020-04-22 11:34:09","updateTime":"2020-04-21 09:18:57","sumUpDoorPropaganda":0}]}
     * @catalog 社区后台管理/督导员、巡检员管理
     * @title 巡检员列表
     * @param id 非必须 String 员工ID
     * @method get
     * @description 巡检员列表，不包括参数ID对应巡检员
     * @url /cms/admin/supervisor/getXunjinayuan
     */
    @RequestMapping("/getXunjinayuan")
    public BaseResult getXunjinayuan(String id) {
        return BaseResult.ok(supervisorUserService.getXunjinayuan(id));
    }

    /**
     * showdoc
     *
     * @return {"status":200,"msg":"SUCCESS","data":{"id":"158711800317312","phone":"15977772222","username":"刘德华","workId":"3456","password":"E10ADC3949BA59ABBE56E057F20F883E","roleId":"158711800303859","idCard":"110101199003074397","createTime":"2020-04-21 20:57:31","updateTime":"2020-04-17 18:38:10","superiorId":"158711800317392","sumUpDoorPropaganda":0,"supervisorRole":{"id":"158711800317312","name":"督导员","createTime":1587502651000,"updateTime":1587148690000}}}
     * @catalog 社区后台管理/督导员、巡检员管理
     * @title 员工详情
     * @method get
     * @param id 非必须 String 员工ID
     * @description 员工详情
     * @url /cms/admin/supervisor/detail
     */
    @RequestMapping("/detail")
    public BaseResult detail(String id) {
        return BaseResult.ok(supervisorUserService.detail(id));
    }

    /**
     * showdoc
     *
     * @return {"status":200,"msg":"SUCCESS","data":[{"id":"158711800303859","name":"督导员","createTime":1587146823000,"updateTime":1587146820000},{"id":"158711800398756","name":"巡检员","createTime":1587148635000,"updateTime":1587146826000}]}
     * @catalog 社区后台管理/督导员、巡检员管理
     * @title 角色列表
     * @method get
     * @description 角色列表
     * @url /cms/admin/supervisor/role
     */
    @RequestMapping("/role")
    public BaseResult getRole() {
        return BaseResult.ok(supervisorUserService.getRole());
    }

    /**
     * showdoc
     *
     * @return {"status":200,"msg":"SUCCESS","data":null}
     * @catalog 社区后台管理/督导员、巡检员管理
     * @title 添加或者修改巡检员或督导员
     * @param id 非必须 String 员工ID
     * @param phone 必须 String 员工电话
     * @param username 必须 String 员工姓名
     * @param workId 必须 String 员工工号
     * @param roleId 必须 String 角色ID
     * @param idCard 必须 String 员工身份证
     * @param superiorId 非必须 String 督导员上级的ID，非督导员则为空
     * @param sumUpDoorPropaganda 非必须 Integer 督导员上门推广APP任务量
     * @method post
     * @description 添加或者修改巡检员或督导员
     * @url /cms/admin/supervisor/insertOrUpdate
     */
    @RequestMapping("/insertOrUpdate")
    public BaseResult insertOrUpdate(@RequestBody @Valid SupervisorUserDto supervisorUserDto) {
        return supervisorUserService.insertOrUpdate(supervisorUserDto);
    }

    /**
     * showdoc
     *
     * @return {"status":200,"msg":"SUCCESS","data":null}
     * @catalog 社区后台管理/督导员、巡检员管理
     * @title 添加或者修改巡检员或督导员
     * @param id 非必须 String 督导员ID
     * @param ids 必须 String数组 分类桶设备号数组
     * @method post
     * @description 添加或者修改巡检员或督导员
     * @url /cms/admin/supervisor/updateSupervisorTrashCan
     */
    @RequestMapping("/updateSupervisorTrashCan")
    public BaseResult updateSupervisorTrashCan(String id, String... ids) {
        if (StringUtils.isBlank(id) || ObjectUtils.isEmpty(ids) || ids.length < 1){
            return BaseResult.build(StatusCode.PARAMETER_WRONG);
        }
        return supervisorUserService.updateSupervisorTrashCan(id,ids);
    }

    /**
     * showdoc
     *
     * @return {"status":200,"msg":"SUCCESS","data":null}
     * @catalog 社区后台管理/督导员、巡检员管理
     * @title 启用或者停用员工
     * @param id 非必须 String 员工ID
     * @method post
     * @description 启用或者停用员工
     * @url /cms/admin/supervisor/useOrStop
     */
    @RequestMapping("/useOrStop")
    public BaseResult useOrStop(String id) {
        if (StringUtils.isBlank(id)) {
            return BaseResult.build(StatusCode.PARAMETER_WRONG);
        }
        return BaseResult.ok(supervisorUserService.useOrStop(id));
    }



    /**
     * showdoc
     *
     * @param supervisorId 非必须 String 督导员ID
     * @param userId       非必须 String 用户ID
     * @param taskType     非必须 String 任务类型
     * @return {"status":200,"msg":"SUCCESS","data":{"total":1,"list":[{"id":"158720218284282","supervisorId":"158711800317392","taskType":"验证户主","userId":"158502014539730","createTime":"2020-04-18 09:29:43","updateTime":"2020-04-18 17:29:48"}],"pageNum":1,"pageSize":10,"size":1,"startRow":1,"endRow":1,"pages":1,"prePage":0,"nextPage":0,"isFirstPage":true,"isLastPage":true,"hasPreviousPage":false,"hasNextPage":false,"navigatePages":8,"navigatepageNums":[1],"navigateFirstPage":1,"navigateLastPage":1}}
     * @catalog 社区后台管理/督导员、巡检员管理
     * @title 工作记录
     * @method get
     * @description 工作记录
     * @url /cms/admin/supervisor/workRecord
     */
    @RequestMapping("/workRecord")
    public BaseResult workRecord(@RequestParam(defaultValue = "1") Integer pageNum,
                                 @RequestParam(defaultValue = "10") Integer pageSize,
                                 String workId,
                                 String phone,
                                 String taskType) {
        return supervisorUserService.workRecord(pageNum, pageSize, workId, phone, taskType);
    }

    /**
     * showdoc
     *
     * @return {"status":200,"msg":"SUCCESS","data":{"id":"158720277633933","supervisorId":"1","taskType":"验证户主","userId":"158502014539731","createTime":"2020-04-18 09:39:36","updateTime":"2020-04-18 17:39:41"}}
     * @catalog 社区后台管理/督导员、巡检员管理
     * @title 工作记录详情
     * @param id 非必须 String 记录ID
     * @method get
     * @description 工作记录详情
     * @url /cms/admin/supervisor/workRecordDetail
     */
    @RequestMapping("/workRecordDetail")
    public BaseResult workRecordDetail(String id) {
        return supervisorUserService.workRecordDetail(id);
    }

    /**
     * showdoc
     *
     * @return {"status":200,"msg":"SUCCESS","data":null}}
     * @catalog 社区后台管理/督导员、巡检员管理
     * @title 删除工作记录
     * @param id 非必须 String 记录ID
     * @method delete
     * @description 删除工作记录
     * @url /cms/admin/supervisor/delWorkRecord
     */
    @RequestMapping("/delWorkRecord")
    public BaseResult delWorkRecord(String id) {
        return supervisorUserService.delWorkRecord(id);
    }
}
